<%--
  Created by IntelliJ IDEA.
  User: sofwin
  Date: 2021/7/17
  Time: 14:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%String path = request.getContextPath()+"/";%>
<html>
<head>
    <base href="<%=path%>"/>
    <title>Title</title>
    <script type="text/javascript" src="bootstrap/js/jquery.min.js"></script>

    <link href="bootstrap/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
    <script type="text/javascript" src="bootstrap/ztree/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="bootstrap/ztree/js/jquery.ztree.excheck.js"></script>

    <script type="text/javascript" src="bootstrap/js/plugins/layer/layer.min.js"></script>
    <script type="text/javascript" src="bootstrap/js/ry.js"></script>

</head>
<body>
    <div id="tree" class="ztree"></div>
    <button type="button" id="save" class="btn btn-default">
        <i class="fa fa-save"></i>
        保存</button>
</body>
<script>
    var setting={
        data:{
            simpleData:{
                enable:true
            }
        },
        check:{
            enable:true
        }
    };
    var $tree;
    $(function(){
        // 发异步请求返回json数组 (id name pId)
        $.post('role/permission',"{roleId:'${roleId}'}",function(ret){
            $tree =  $.fn.zTree.init($("#tree"), setting, ret.data);
        })

        $("#save").click(function(){
            // 将当前树中选中的节点的id   resource_id
            // 当前角色的id  ${roleId}
            let treeNodes = $tree.getCheckedNodes(true);
            let resourceIds=new Array();
            for(let i=0;i<treeNodes.length;i++){
                resourceIds.push(treeNodes[i].id);
            }
            $.modal.saveWindow('role/savePermission',{ids:resourceIds,roleId:'${roleId}'});
        })

    });
</script>
</html>
